# -*- coding: utf-8 -*-

# -------------------------------
# Author    : linlingwei
# Email     : 951035650@qq.com
# File Name : t3.py
# Date      : 2019/8/1 
# IDE       : PyCharm
# Version   : 1.0.1
# -------------------------------
# 选择除 character asset 外的组（列如场景大组），运行代码
#
#
# -------------------------------
import maya.cmds as mc
import maya.mel as mel

def cnt(at):
    for tr in ["t", ]:
        md = mc.createNode("multiplyDivide", name=at + "_anim")
        for xyz in ["x", 'y', 'z']:
            pp = mc.listConnections(at + "." + tr + xyz, d=0, s=1, p=1)
            if pp:
                mc.connectAttr(pp[0], md + ".i1" + xyz, f=1)
                mc.connectAttr(md + ".o" + xyz, at + "." + tr + xyz, f=1)
                mc.setAttr(md + ".i2" + xyz, .01)

sel = mc.ls(sl=1)
global_loc = mc.spaceLocator(name="global_scale_loc")[0]
for sl in sel:
    mc.parentConstraint(global_loc, sl, mo=1)
    mc.scaleConstraint(global_loc, sl, mo=1)
assets = mc.ls("*:global_ctrl") + mc.ls("*:*:global_ctrl")
par = []
for at in assets:
    print at
    pt = mc.parentConstraint(global_loc, at.replace("global_ctrl", "global_ctrl_Con"), mo=1)[0]
    par.append(pt)
    nn = at.rsplit(":", 1)[0]
    attr = "%s:globalScale_MD.i2x" % (nn)
    cmd = 'CBselectConnection "%s";' % attr
    attr = at + ".globalScale"
    mel.eval('CBdeleteConnection "%s";' % attr)
    value = mc.getAttr(attr)
    mc.setAttr(attr, value * 0.01)
    cnt(at)

mc.setAttr(global_loc + ".s", 0.01, 0.01, 0.01)
mc.delete(par)

if __name__ == '__main__':
    pass